package cn.lovecyy.mockjson.core.type;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.lovecyy.mockjson.core.domain.TypeConfig;
import cn.lovecyy.mockjson.core.gen.MockRandomUtils;

/**
 * RepeatTypeMocker
 *
 * @author Yakir
 */
public class RepeatTypeMocker implements TypeMocker {

	@Override
	public String getType() {
		return "repeat";
	}

	@Override
	public Object mock(TypeConfig config) {
		String mainParam = config.getMainParam();
		String format = config.getFormat();
		if (StrUtil.isEmpty(format)) {
			format = "1";
		}
		return MockRandomUtils.repeatString(mainParam, Integer.valueOf(format));
	}

}
